package com.ctgu.rabbitmq.rabbitmq.idempotent;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ ClassName IdempotentConfig
 * @ Author Alex2
 * @ Date 2025/8/18 14:53
 **/
@Configuration
public class IdempotentConfig {
    // 幂等交换机
    public static final String IDEMPOTENT_EXCHANGE = "idempotent_exchange";
    public static final String IDEMPOTENT_QUEUE = "idempotent_queue";
    public static final String IDEMPOTENT_ROUTING_KEY = "idempotent_routing_key";

    // 幂等交换机
    @Bean
    public DirectExchange idempotentExchange() {
        return new DirectExchange(IDEMPOTENT_EXCHANGE);
    }

    // 幂等队列
    @Bean
    public Queue idempotentQueue() {
        return QueueBuilder.durable(IDEMPOTENT_QUEUE).build();
    }

    // 绑定队列到交换机
    @Bean
    public Binding idempotentBinding() {
        return BindingBuilder.bind(idempotentQueue())
                .to(idempotentExchange())
                .with(IDEMPOTENT_ROUTING_KEY);
    }
}